﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Collector
{
    class Profile
    {
        public static void LoadProfile()
        {
            string strPath = AppDomain.CurrentDomain.BaseDirectory;
            _file = new IniFile(strPath + "zhx_Cfg.ini");
            G_BAUDRATE = _file.ReadString("CONFIG", "BaudRate", "9600");    //读数据，下同
            G_DATABITS = _file.ReadString("CONFIG", "DataBits", "8");
            G_STOP = _file.ReadString("CONFIG", "StopBits", "1");
            G_PARITY = _file.ReadString("CONFIG", "Parity", "None");
            if (G_BAUDRATE == "" || G_BAUDRATE == null)
            {
                G_BAUDRATE = "9600";
            }
            if (G_DATABITS == "" || G_DATABITS == null)
            {
                G_DATABITS = "8";
            }
            if (G_STOP == "" || G_STOP == null)
            {
                G_STOP = "1";
            }
            if (G_PARITY == "" || G_PARITY == null)
            {
                G_PARITY = "None";
            }
        }

        public static void SaveProfile()
        {
            string strPath = AppDomain.CurrentDomain.BaseDirectory;
            _file = new IniFile(strPath + "zhx_Cfg.ini");
            _file.WriteString("CONFIG", "BaudRate", G_BAUDRATE);            //写数据，下同
            _file.WriteString("CONFIG", "DataBits", G_DATABITS);
            _file.WriteString("CONFIG", "StopBits", G_STOP);
            _file.WriteString("CONFIG", "G_PARITY", G_PARITY);
        }

        private static IniFile _file;//内置了一个对象

        public static string G_BAUDRATE = "9600";//给ini文件赋新值，并且影响界面下拉框的显示
        public static string G_DATABITS = "8";
        public static string G_STOP = "1";
        public static string G_PARITY = "None";
    }
}
